/*
 * 项目名称:项目名称
 * 类名称:GanaProductController.java
 * 包名称:com.tongyi.modules.gana.controller
 * @author 惠州市酷天科技有限公司
 * @date 2024-06-25 20:19:44
 * Copyright (c) 2019-2021 惠州市酷天科技有限公司
 */
package com.tongyi.modules.gana.controller;

import com.tongyi.common.annotation.SysLog;
import com.tongyi.common.utils.RestResponse;
import com.tongyi.core.PageInfo;
import com.tongyi.modules.gana.entity.GanaProductEntity;
import com.tongyi.modules.gana.service.GanaProductService;
import com.tongyi.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Controller
 *
 * @author 惠州市酷天科技有限公司
 * @date 2024-06-25 20:19:44
 */
@RestController
@RequestMapping("gana/product")
public class GanaProductController extends AbstractController {
    @Autowired
    private GanaProductService ganaProductService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @GetMapping(value="/listAll")
    @RequiresPermissions("gana:product:list")
    public RestResponse listAll(@RequestParam Map<String, Object> params) {
        List<GanaProductEntity> list = ganaProductService.listAll(params);
        return RestResponse.success("list", list);
    }

    /**
     * 分页查询
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @GetMapping("/list")
    @RequiresPermissions("gana:product:list")
    public RestResponse list(@RequestParam(value = "page",defaultValue = "1") int current,@RequestParam(value = "limit",defaultValue = "10")int size,@RequestParam Map<String, Object> params) {
        PageInfo page = ganaProductService.listPage(current,size,params);
        return RestResponse.success("page", page);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return RestResponse
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("gana:product:info")
    public RestResponse info(@PathVariable("id") Long id) {
        GanaProductEntity ganaProduct = ganaProductService.getById(id);
        return RestResponse.success("info", ganaProduct);
    }

    /**
     * 新增
     *
     * @param entity
     * @return RestResponse
     */
    @SysLog("新增")
    @PostMapping("/save")
    @RequiresPermissions("gana:product:save")
    public RestResponse save(@RequestBody GanaProductEntity entity) {
        ganaProductService.addEntity(entity);
        return RestResponse.success();
    }

    /**
     * 修改
     *
     * @param entity
     * @return RestResponse
     */
    @SysLog("修改")
    @PostMapping("/update")
    @RequiresPermissions("gana:product:update")
    public RestResponse update(@RequestBody GanaProductEntity entity) {
        ganaProductService.updateEntity(entity);
        return RestResponse.success();
    }

    /**
     * 根据主键删除
     *
     * @param ids
     * @return RestResponse
     */
    @SysLog("删除")
    @PostMapping("/delete")
    @RequiresPermissions("gana:product:delete")
    public RestResponse delete(@RequestBody Long[] ids) {
        ganaProductService.deleteBatch(ids);
        return RestResponse.success();
    }
}
